#include "../common/config.h"
#include <boost/lexical_cast.hpp>
#include <Wt/WGridLayout>
#include <Wt/WGroupBox>
#include <Wt/WLabel>
#include <Wt/WLength>
#include <Wt/WLineEdit>
#include <Wt/WVBoxLayout>
#include "Pad.h"
#include "ConfigPage.h"
#include "../httpproxy/httpproxy.h"

using namespace std;
using namespace Wt;

ConfigPage::ConfigPage(WContainerWidget *parent)
	: WContainerWidget(parent)
{
	HTTPConfig& main_config = HTTPProxy::getInstance().getConfig();

	WVBoxLayout *root_layout = new WVBoxLayout(this);

	WGroupBox *proxy_section = new WGroupBox("Proxy Settings", this);
	WGridLayout *proxy_layout = new WGridLayout(proxy_section);
	proxy_layout->addWidget(new WLabel("Port"), 0, 0, AlignLeft | AlignTop);
	m_proxy_port = new WLineEdit(proxy_section);
	m_proxy_port->setTextSize(5);
	m_proxy_port->setText(boost::lexical_cast<string>(main_config.getListeningPort()));
	proxy_layout->addWidget(m_proxy_port, 0, 1, AlignLeft | AlignTop);
	
	proxy_section->setLayout(proxy_layout);
	proxy_section->setMinimumSize(WLength(600), WLength());

	root_layout->addWidget(new VerticalPad(100), 0, AlignCenter | AlignTop);
	root_layout->addWidget(proxy_section, 1, AlignCenter | AlignTop);

	setLayout(root_layout);
}
